package indi.mumu.service;

import indi.mumu.common.model.Clothes;
import indi.mumu.common.model.Saleorder;
import indi.mumu.common.model.Saleorderitem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SaleOrderItemService{
	/**

	 * 

	 * @param item

	 * @return 添加订单详情

	 */
	public Map<String,Object> addItem(Saleorderitem item){
		Map<String,Object> result = new HashMap<String,Object>();
		if(item.save()){
			result.put("status", true);
			result.put("data", "保存成功");
		}else{
			result.put("status", false);
			result.put("data", "保存失败");
		}
		return result;
	}
	/**

	 * 

	 * @param saleOrderId

	 * @return 通过订单ID 获得指定订单详情

	 */
	public Map<String,Object> getAimItem(String saleOrderId){
		Map<String,Object> result = new HashMap<String, Object>();
		String sql = "select * from saleorderitem as s where s.saleOrder_id='"+saleOrderId+"'";
		String saleOrderSql = "select * from saleorder as s where s.saleOrder_id='"+saleOrderId+"'";
		List<Saleorder> saleOrder = Saleorder.dao.find(saleOrderSql);
		List<Saleorderitem> saleItems = Saleorderitem.dao.find(sql);
		List<List<Clothes>> goods = new ArrayList<List<Clothes>>();
		if(saleItems.size()==0){
			result.put("status", false);
			result.put("data1", "找不到订单");
			result.put("data2", "找不到订单");
		}else{
			
			for(int i=0;i<saleItems.size();i++){
				String itemId = saleItems.get(i).getProductId();
				//通过订单获得所够商品

				String sql1 = "select * from clothes as g where g.product_id ='"+itemId+"'";

				List<Clothes> good = Clothes.dao.find(sql1);
				goods.add(good);
			}
			
//			result.put("status", true);
//			result.put("data1", saleOrder);
//			result.put("data2", goods);
			result.put("data3", saleItems);
		}
		return result;
	}
	/**

	 * 

	 * @param saleItem

	 * @return 更新订单详情

	 */
	public Map<String,Object> updataSaleItem(Saleorderitem saleItem){
		Map<String,Object> result = new HashMap<String, Object>();
		if(saleItem.update()){
			result.put("status", true);
			result.put("data", "更新成功");
		}else{
			result.put("status", false);
			result.put("data", "更新失败");
		}
		return result;
	}

}
